<template>
  <div class="page-layout" :style="props.pageStyle">
    <div class="page-layout-content">
      <slot></slot>
    </div>
    <u-modal v-model="show" :show-cancel-button="false" :show-confirm-button="false" :show-title="false" :title-style="{ color: '#222222' }">
      <div class="u-model-content">
        <div class="title">{{ modelData.title }}</div>
        <view class="slot-content">
          <rich-text :nodes="modelData.content"></rich-text>
        </view>
        <div class="btns">
          <div class="btn" @click="bindModalSuccess('error')">取消</div>
          <div class="btn is-success" @click="bindModalSuccess('success')">确定</div>
        </div>
      </div>
    </u-modal>
  </div>
</template>
<script lang="ts" setup>
import { ref, shallowRef, provide } from 'vue';

const props = defineProps<{
  pageStyle?: string;
}>();
const show = ref(false);

const modelData = shallowRef({
  title: '提示',
  content: '确定要删除吗确定要删除吗确定要删除吗确定要删除吗确定要删除吗确定要删除吗确定要删除吗确定要删除吗确定要删除吗？',
  callback: ({ type }) => {},
});

const openModal = (data) => {
  modelData.value = data;
  show.value = true;
};
const bindModalSuccess = (type) => {
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
  modelData.value.callback && modelData.value.callback({ type });
  setTimeout(() => {
    show.value = false;
  }, 500);
};

provide('openModal', openModal);
defineExpose({
  openModal,
});
</script>

<style lang="scss" scoped>
.page-layout {
  width: 100vw;
  min-height: 100vh;
}
.page-layout-content {
  min-width: 100%;
  min-height: 100%;
  padding-bottom: 0;
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
}

.u-model-content {
  background: #ffffff;
  border-radius: 16rpx 16rpx 16rpx 16rpx;
  padding: 32rpx;

  .title {
    height: 42rpx;
    font-weight: bold;
    font-size: 32rpx;
    color: #222222;
    line-height: 42rpx;
    text-align: center;
  }

  .slot-content {
    margin: 24rpx 0 40rpx;
    text-align: center;
  }

  .btns {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16rpx;
    padding: 0 0 32rpx;

    .btn {
      width: 284rpx;
      height: 72rpx;
      background: #f3f7f8;
      border-radius: 4rpx 4rpx 4rpx 4rpx;
      font-weight: 400;
      font-size: 28rpx;
      color: #6f6f6f;
      line-height: 72rpx;
      text-align: center;

      &.is-success {
        background: linear-gradient(90deg, #f32f1a 0%, #f68a2d 100%);
        color: #ffffff;
      }
    }
  }
}
</style>
